//
// Created by lingzhitech on 25-11-5.
//

#ifndef STRBLOBPTR_HPP
#define STRBLOBPTR_HPP
#include "StrBlob.h"



class StrBlobPtr {
    friend bool operator==(const StrBlobPtr &, const StrBlobPtr &);
    friend bool operator!=(const StrBlobPtr &, const StrBlobPtr &);
public:
    StrBlobPtr(): current_position(0) { }
    StrBlobPtr(StrBlob &a, size_t size = 0):
    wptr(a.data), current_position(size) { }
    StrBlobPtr& operator++();
    StrBlobPtr& operator--();
    StrBlobPtr operator++(int);
    StrBlobPtr operator--(int);
    std::string& operator*() const;
    std::string* operator->() const;
    std::string& deref() const;
    StrBlobPtr& incr(); // prefix version
private:
    // check returns a shared_ptr to the vector if the check succeeds
    std::shared_ptr<std::vector<std::string>>
    check(std::size_t, const std::string&) const;
    // store a weak_ptr, which means the underlying vector might be destroyed
    std::weak_ptr<std::vector<std::string>> wptr;
    std::size_t current_position; // current position within the array
};



#endif //STRBLOBPTR_HPP
